package com.atguigu.h_concurrentmodification;

import java.util.*;

public class MyConCurrentModificationException {
    public static void main(String[] args) {
        /*arrayList线程不安全 ConcurrentModificationException 没加锁*/
//        ArrayList<String> list = new ArrayList<>();
        /*vetor线程安全 因为加锁了*/
//        Vector<String> list = new Vector<>();
        /*使用辅助工具类*/
        List<String> list = Collections.synchronizedList(new ArrayList<String>());

        for (int i = 0; i < 30; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    list.add(UUID.randomUUID().toString().substring(0,6));
                    System.out.println(list);
                }
            }).start();
        }
    }
}
